//
//  UUSupplierRegisterVC.m
//  UUCharterSupplier
//
//  Created by ZhangAo on 16/02/2018.
//  Copyright © 2018 UUCharter. All rights reserved.
//

#import "UUSupplierRegisterVC.h"
#import "UUHybridManager+CharterSupplier.h"
#import <UUFoundation/DKProgressHUD.h>
#import "AppDelegate.h"

@interface UUSupplierRegisterVC ()

@property (nonatomic, assign) BOOL isSecondStep;
@property (nonatomic, copy) void (^submitSecondData)(NSDictionary *data);

@end

@implementation UUSupplierRegisterVC

- (void)viewDidLoad {
    self.editable = YES;
    
    [super viewDidLoad];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (NSString *)fullName {
    return @"供应商注册";
}

- (NSURLRequest *)editRequest {
    if (self.isSecondStep) {
        return GetHybridManager().registerSecondURLRequest;
    } else {
        return GetHybridManager().registerFirstURLRequest;
    }
}

- (void)addOrUpdate:(NSDictionary *)data {
    if (self.isSecondStep) {
        self.submitSecondData(data);
    } else {
        UUSupplierRegisterVC *secondStepVC = [UUSupplierRegisterVC instanceOfAppropriate];
        secondStepVC.isSecondStep = YES;
        secondStepVC.previewData = self.previewData;
        WEAK_SELF();
        [secondStepVC setSubmitSecondData:^(NSDictionary *secondData) {
            NSMutableDictionary *result = [data mutableCopy];
            [result addEntriesFromDictionary:secondData];
            [weakSelf registerSupplierWithData:result];
        }];
        [self.navigationController pushViewController:secondStepVC animated:YES];
    }
}

- (NSDictionary *)previewFields {
    return self.previewData;
}

- (void)registerSupplierWithData:(NSDictionary *)data {
    BLOCK_SAFE_CALLS(self.completeBlock, data);
}

@end
